package com.kuang;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * ClassName: FileInPutOutPutStreamTest
 * Description:
 * Date: 2021/3/17 14:18
 * Company: TravelSky
 *
 * @author YangXin
 */
public class FileInPutOutPutStreamTest {

    @Test
    public void fileInPutStreamTest(){
        FileInputStream fis = null;
        FileOutputStream fos = null;
        //造文件
        File file = new File("src\\main\\resources\\imgs\\微信截图_20210311203000.png");
        File file1 = new File("src\\main\\resources\\imgs\\复制的.png");
        //造流
        try {
            fis = new FileInputStream(file);
            fos = new FileOutputStream(file1);
            //读取数据
            byte[] bytes = new byte[5];
            int len;
            while ((len = fis.read(bytes)) != -1){
                fos.write(bytes,0,len);
            }
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if (fis != null) {
                try {
                    //关闭流
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }if (fos != null) {
                try {
                    //关闭流
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
